import pandas as pd
import numpy as np
from sqlalchemy import create_engine


def write_sql(engine):
    frame = pd.DataFrame(np.arange(20).reshape(4,5),
                         columns=['white', 'red', 'blue', 'black', 'green'])
    print(frame)
    frame.to_sql('colors', engine, if_exists="append", index=False)


def read_sql(engine):

    frame = pd.read_sql('colors', engine)
    print(frame)


def read_all_table_name(engine):
    tables = engine.execute("select name from sqlite_master where type='table' order by name")
    return [r[0] for r in tables]


if __name__ == '__main__':
    engine = create_engine('sqlite:///E:\\MarketData\\arbitrage_tick\\arbitrage_tick.db')
    #write_sql(engine)
    #read_sql(engine)
    tables = read_all_table_name(engine)
    for t in tables:
        print(t)
